<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Appliance_model extends CI_Model {

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    function add_appliance($_POST){
		$this->db->query("INSERT INTO appliance_info VALUES (
			'".$_POST["student_number"]."',
			'".$_POST["control_number"]."',
			'".$_POST["type_of_appliance"]."',
			'".$_POST["date_installed"]."',
			'".$_POST["date_cancelled"]."',
			'".$_POST["remark"]."'
			)");
	}
	
	function check_appliance($_POST){
		$query = $this->db->query("
			SELECT * FROM appliance_info 
			WHERE student_number='".$_POST["student_number"]."'
			and control_number='".$_POST["control_number"]."'");
		return $query->num_rows()>0?1:0;
	}
	
	function get_appliance($_POST){
		return $this->db->query("
			SELECT * FROM appliance_info 
			WHERE student_number='".$_POST["student_number"]."'
			and control_number='".$_POST["control_number"]."'");
	}
	
	function get_appliances($_POST){
		return $this->db->query("
			SELECT * FROM appliance_info 
			WHERE student_number='".$_POST["student_number"]."'");
	}
	
	function delete_appliance($_POST){
		$this->db->query("DELETE FROM appliance_info WHERE student_number='".$_POST['student_number']."' and control_number='".$_POST['choice']."'");
	}
	
	function edit_appliance($_POST){
		$this->db->query("UPDATE appliance_info SET
			type_of_appliance='".$_POST["type_of_appliance"]."',
			date_installed='".$_POST["date_installed"]."',
			date_cancelled='".$_POST["date_cancelled"]."',	
			remark='".$_POST["remark"]."'
			WHERE student_number='".$_POST["student_number"]."' and control_number='".$_POST["control_number"]."'
			");
	}

}
/* End of file appliance_model.php */
/* Location: ./application/models/appliance_model.php */
?>